<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>员工管理</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/jstree/jstree.min.css" rel="stylesheet">
    <link href="../plugin/bootstrap-fileinput-master/fileinput.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../plugin/fileupload/css/jquery.fileupload.css">
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-select/bootstrap-select.min.css" rel="stylesheet"/>

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../js/base.js'></script>
    <!--<script src="../plugin/soulUtils/soul_utils.js"></script>-->
    <script src='../plugin/jquery-3.2.1/jquery.form.js'></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/jstree/jstree.min.js"></script>
    <script src="../plugin/bootstrap-fileinput-master/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-select/bootstrap-select.js"></script>
    <script src="../plugin/bootstrap-select/defaults-zh_CN.js"></script>
    <script src="../plugin/wangEditor-3.0.15/wangEditor.min.js"></script>
</head>

<body>
<div class="modal fade" data-backdrop="static" id="staffManager_privilege_edit_modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>用户权限编辑</b>
                </h4>
            </div>
            <div class="modal-body">
                <form id="staffManager_privilege_edit_form" method="post">
                    <div class="form-group">
                        <label>权限列表</label>
                        <div id="staffManager_privilege_edit_form_privIds"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="staffManager.privilege.save()">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" data-backdrop="static" id="staffManager_modal_edit_detail">
    <div class="modal-dialog modal-lg ">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>用户资质</b>
                </h4>
            </div>
            <div class="modal-body">
                <div id="staffManager_modal_edit_detail_editor"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="staffManager.detail.save()">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" data-backdrop="static" id="staffManager_hospitalManage_edit_modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>管辖医院</b>
                </h4>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label">管辖医院</label>
                    <div class="col-sm-9">
                        <select id = 'smallProgramPrivId' class="form-control selectpicker" data-live-search="true" multiple>
                        </select>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="staffManager.hospitalManage.save()">保存</button>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'staffManager';
        var query = [{
            id: 'department',
            type: 'select',
            name: '所属部门',
            paramName: 'departmentId',
            items: 'department/selectItem'
        },{
            id: 'hospital',
            type: 'select',
            name: '医院名称',
            paramName: 'hospitalId',
            items: 'hospital/selectItem'
        },{
            id: 'realname',
            type: 'text',
            name: '真实姓名',
            paramName: 'realname',
            palceholder: ''
        }, {
            id: 'phone',
            type: 'text',
            name: '电话号码',
            paramName: 'phone',
            palceholder: ''
        }, {
            id: 'username',
            type: 'text',
            name: '用户名',
            paramName: 'username',
            palceholder: ''
        }];
        var toolbar = {
            default: [false, true, true, true],// back;add;edit;remove
            dialog: [60, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [
                   {
                       name: '编辑用户权限',
                       onclick: 'showStaffPrivilegeModal'
                   },
                {
                    name: '重置密码',
                    onclick: 'resetPassword'
                }, {
                    name: '用户资质',
                    glyphicon: 'list',
                    onclick: 'showQualification',
                }
            ]
        };
        var formElement = [{
            action: [false, true],
            type: 'hidden',
            name: 'staffId',
        }, {
            action: [true, true],
            type: 'text',
            label: '用户名',
            name: 'username',
        }, {
            action: [true, false],
            type: 'text',
            label: '密码',
            name: 'password',
        }, {
            action: [true, true],
            type: 'text',
            label: '电话号码',
            name: 'phone',
        }, {
            action: [true, true],
            type: 'text',
            label: '真实姓名',
            name: 'realname',
        }, {
            action: [true, true],
            type: 'text',
            label: '技术方向',
            name: 'technicalDirection',
        }, {
            action: [true, true],
            id: 'roleId',
            type: 'select',
            label: '角色',
            name: 'roleId',
            items: 'role/selectItem'
        },{
            action: [true, true],
            id: 'hospitalId',
            type: 'select',
            label: '所属医院',
            name: 'hospitalId',
            items: 'hospital/selectItem'
        }, {
            action: [true, true],
            id: 'departmentId',
            type: 'select',
            label: '所属部门',
            name: 'departmentId',
            items: 'department/selectItem'
        }];
        var bootstrapTable = {
            columns: [{
                radio: true
            }, {
                field: 'hospitalName',
                title: '所属医院',
            }, {
                field: 'departmentName',
                title: '所属部门',
            },{
                field: 'username',
                title: '用户名',
            },{
                field: 'phone',
                title: '电话号码',
            },  {
                field: 'realname',
                title: '真实姓名',
            },  {
                field: 'technicalDirection',
                title: '技术方向',
            }, {
                field: 'roleName',
                title: '角色',
            }, {
                field: 'privJson',
                title: '后台权限明细',
                align: 'center',
                formatter: function (value, row, index) {
                    var priv = '';
                    if (''== value) {
                        return  priv = "无";
                    }
                    var privJson = JSON.parse(value);

                    for (i in privJson) {
                        if (privJson[i].parentId == null) {
                            priv += privJson[i].name + ','
                        }
                    }
                    if (priv.length > 0) {
                        priv = priv.substring(0, priv.length - 1);
                    } else {
                        priv = '无';
                    }
                    return priv;
                }
            }, {
                field: 'smallProgramPrivId',
                title: '操作',
                formatter: function (value, row, index) {
                    var arr = row.manageHospitalId;
                    if (value == 10){
                        return '<a onclick="staffManager.hospitalManage(\''+arr+'\')" href="#">管辖医院</a>';
                    }
                    return "无"
                }
            }]
        };
        staffManager = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);
        staffManager.privilege = {};

        staffManager.onAddModalShowBefore = function () {
            $('#staffManager_modal_add input[name="username"]').val("");
            $('#staffManager_modal_add input[name="password"]').val("");
            $('#staffManager_modal_add input[name="phone"]').val("");
            $('#staffManager_modal_add input[name="realname"]').val("");
            $('#staffManager_modal_add input[name="technicalDirection"]').val("");
            return true;
        };

        staffManager.showStaffPrivilegeModal = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staffManager_table');
            if (!row) return false;
            staffManager.privilege.currentStaffId = row.staffId;
            var resp = AjaxUtil.getJson('privilege/list','limit=500&offset=0');
            if (!resp) return false;
            var jsTreeData = JsTreeUtil.createPrivTree('#staffManager_privilege_edit_form_privIds', resp.obj.rows, row.privIds);
            $('#staffManager_privilege_edit_modal').modal('show');
        };
        staffManager.privilege.save = function () {
            var staffPrivIds = JsTreeUtil.getCheck('#staffManager_privilege_edit_form_privIds');
            var resp = AjaxUtil.postJson('staffManager/editPriv', {
                staffId: staffManager.privilege.currentStaffId,
                privIds: staffPrivIds
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#staffManager_table').bootstrapTable('refresh');
                $('#staffManager_privilege_edit_modal').modal('hide');
            }
        };
        staffManager.onEditModalShowBefore = function (row) {
            row.createDate = FormatUtil.formatDateTime(row.createDate);
            return row;
        };
        staffManager.onRemoveSubmitBefore = function (row) {
            row.createDate = FormatUtil.formatDateTime(row.createDate);
            return row;
        };
        staffManager.resetPassword = function (row) {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staffManager_table');
            row.createDate = '';
            var resp = AjaxUtil.postJson("staffManager/resetPassword", row);
            SwalUtil.success(resp.msg);
        }


        staffManager.showQualification = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staffManager_table');
            if (!row) return false;
            staffManager.detail.currentId = row.staffId;
            editor.txt.html(row.qualification || '');
            $('.w-e-text-container').css('height', '500px')
            $('#staffManager_modal_edit_detail').modal('show');
        };

        //当用户选择角色为区域经理时,管辖医院跟所属医院发生变化
        $('#staffManager_form_add_roleId').change(function () {
            var  addStaffRoleId=$('#staffManager_form_add_roleId').val();
            var resp = AjaxUtil.postJson('role/getSmallProgram', {
                roleId: addStaffRoleId,
            });
           if(resp.obj==10){
               $('#staffManager_form_add_hospitalId').css('disabled',disabled );
           }else{

           }
        });

        staffManager.detail = {};
        staffManager.detail.currentId = undefined;
        staffManager.detail.save = function () {
            var qualification = editor.txt.html();
            console.log(qualification);
            var resp = AjaxUtil.postJson('staffManager/editQualification', {
                staffId: staffManager.detail.currentId,
                qualification: qualification
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#staffManager_table').bootstrapTable('refresh');
                $('#staffManager_modal_edit_detail').modal('hide');
                editor.txt.html('');
            }

        };

        var E = window.wangEditor;
        var editor = new E('#staffManager_modal_edit_detail_editor');
        editor.customConfig.uploadImgServer = '/wangEditor/uploadImages?token=' + BaseConfig.token;
        editor.customConfig.uploadFileName = 'file';
        // editor.customConfig.uploadImgMaxLength = 1;
        editor.customConfig.uploadImgTimeout = 3 * 60 * 1000;
        editor.create();

        // //点击重置密码显示模态框
        staffManager.resetPassword = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staffManager_table');
            if (!row) return false;
            swal({
                title: '输入重置后的密码',
                input: 'text',
                showCancelButton: true,
            }).then(function (inputValue) {
                var resp = AjaxUtil.postJson('staffManager/resetPassword', {
                    staffId: row.staffId,
                    newPassword:inputValue,
                });

                if (!resp) return;
                if (resp) {
                    SwalUtil.success(resp.msg);
                    $('#staffManager_table').bootstrapTable('refresh');
                }
            })
        };

        staffManager.hospitalManage = function (arr) {
            $('#smallProgramPrivId').empty();
            var resp = AjaxUtil.getJson('hospital/selectItem').obj;
            var s = '';
            for (var i = 0; i < resp.length; i++) {
                s += '<option value="' + resp[i].value + '">' + resp[i].name + '</option>';
            }
            $('#smallProgramPrivId').append(s);
            $('#smallProgramPrivId').selectpicker('refresh');
            arr = arr?arr.split(','):'';
            $('#smallProgramPrivId').selectpicker('val', arr);
            $('#staffManager_hospitalManage_edit_modal').modal('show');
        }

        staffManager.hospitalManage.save = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staffManager_table');
            var value = $('#smallProgramPrivId').val().toString();
            var resp = AjaxUtil.postJson('staffManager/selectValue', {
                staffId: row.staffId,
                selectValue: value,
            });
            if (!resp)return
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#staffManager_hospitalManage_edit_modal').modal('hide');
                $('#staffManager_table').bootstrapTable('refresh');
            }
        }
    });
</script>
</html>